<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="/template/AdminTemplate.xhtml">

    <ui:define name="contentInsert">
        <h:form>
            <p:dataTable id="mealList" var="proposal" value="#{groupBuyingManagedBean.allProposal}" 
                         emptyMessage="Currently no dishes have been added"
                         dynamic ="true" paginator="true" paginatorPosition="top" 
                         rows="20">

                <f:facet name="header">
                    Existing group buying items
                </f:facet>

                <p:column style="width:16px">  
                    <p:rowToggler />  
                </p:column> 

                <p:column headerText="id" >
                    <h:outputText id="id" value="#{proposal.id}" />
                </p:column>
                <p:column headerText="Name">
                    <h:outputText id="name" value="#{proposal.name}" />
                </p:column>
                <p:column headerText="Stakeholder" filterBy="#{proposal.stakeholder.name}">
                    <h:outputText id="stakeholder" value="#{proposal.stakeholder.name}" />
                </p:column>
                <p:column headerText="Submission Time" filterBy="#{proposal.submissionTimeStr}"
                          filterMatchMode="startsWith">
                    <h:outputText id="dos" value="#{proposal.submissionTimeStr}"/> 
                </p:column>
                <p:column headerText="Status" filterBy="#{proposal.status}"
                          filterOptions="#{groupBuyingManagedBean.statusOptions}"  
                          filterMatchMode="exact">
                    <h:outputText id="status" value="#{proposal.status}" />
                </p:column>
                <p:column headerText="Options">
                    <p:commandButton id="approve" value="Approve" ajax="false"
                                     update="mealList" disabled="#{proposal.status eq 'Pending' ? false:true}"
                                     actionListener="#{groupBuyingManagedBean.approveProposal}">
                        <f:attribute name="gbItemId" value="#{proposal.id}" />
                    </p:commandButton>
                    <p:commandButton id="deny" value="Deny" ajax="false"
                                     actionListener="#{groupBuyingManagedBean.denyProposal}"
                                     update="mealList" disabled="#{proposal.status eq 'Pending' ? false:true}">
                        <f:attribute name="gbItemId" value="#{proposal.id}" />
                    </p:commandButton>
                </p:column>


                <p:rowExpansion>  
                    <h:panelGrid id="display" columns="2" cellpadding="4"  >
                        <f:facet name="header">  
                            More information...
                        </f:facet>  

                        <h:outputText value="Offering Price: "/>
                        <h:outputText id="offeringPrice" value="#{proposal.offeredPrice}"/>
                        <h:outputText value="Original Price: "/>
                        <h:outputText id="originalPrice" value="#{proposal.originalPrice}"/>
                        <h:outputText value="Effective start: "/>
                        <h:outputText id="effectiveStart" value="#{proposal.effectiveStartStr}"/>
                        <h:outputText value="Effective start: "/>
                        <h:outputText id="effectiveEnd" value="#{proposal.effectiveEndStr}"/>
                        <h:outputText value="Redemption start: "/>
                        <h:outputText id="redemptionStart" value="#{proposal.redemptionStartStr}"/>
                        <h:outputText value="Redemption end: "/>
                        <h:outputText id="redemptionEnd" value="#{proposal.redemptionEndStr}"/>
                        <h:outputText value="Min Quota: "/>
                        <h:outputText id="minQuota" value="#{proposal.minQuota}"/>
                        <h:outputText value="Max quota: "/>
                        <h:outputText id="maxQuota" value="#{proposal.maxQuota}"/>
                        <h:outputText value="Personal quota: "/>
                        <h:outputText id="personalQuota" value="#{proposal.personalQuota}"/>
                        <h:outputText value="Require booking: "/>
                        <h:outputText id="reqBooking" value="#{proposal.requireBooking}"/>
                        <h:outputText value="Description"/>
                        <h:outputText id="description" value="#{proposal.description}"/>
                        <h:outputText value="Validation"/>
                        <h:outputText id="validation" value="#{proposal.validateRequirements}"/>
                    </h:panelGrid>

                    <br/>
                </p:rowExpansion>
            </p:dataTable>
        </h:form>
    </ui:define>

</ui:composition>
